﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CommunitySystem.PageView.WordAction
{
    public partial class XingZhengJieShaoXinControl : UserControl
    {
        private WordActionService.WordActionClient _client = null;
        public XingZhengJieShaoXinControl()
        {
            InitializeComponent();
            _client = new WordActionService.WordActionClient();
            _client.GetXingZhengJieshaoXingCompleted += new EventHandler<WordActionService.GetXingZhengJieshaoXingCompletedEventArgs>(_client_GetXingZhengJieshaoXingCompleted);
            this.Loaded += new RoutedEventHandler(XingZhengJieShaoXinControl_Loaded);
            _client.DeleteWord_XingZhengJieShaoLetterCompleted += new EventHandler<WordActionService.DeleteWord_XingZhengJieShaoLetterCompletedEventArgs>(_client_DeleteWord_XingZhengJieShaoLetterCompleted);
        }

        void _client_DeleteWord_XingZhengJieShaoLetterCompleted(object sender, WordActionService.DeleteWord_XingZhengJieShaoLetterCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("删除成功!");
                XingZhengJieShaoXinControl_Loaded(null, null);
            }
        }

        void XingZhengJieShaoXinControl_Loaded(object sender, RoutedEventArgs e)
        {
            _client.GetXingZhengJieshaoXingAsync("1=1");
        }

        void _client_GetXingZhengJieshaoXingCompleted(object sender, WordActionService.GetXingZhengJieshaoXingCompletedEventArgs e)
        {
            dgList.ItemsSource = null;
            dgList.ItemsSource = e.Result;
        }
        private XingZhengJieShaoXinWindow wind = null;
        private void ImageButton_Click(object sender, RoutedEventArgs e)
        {
            wind = new XingZhengJieShaoXinWindow(0);
            wind.Show();
            wind.Closed += (sender1, e1) =>
            {
                if (wind.DialogResult == true)
                {
                    XingZhengJieShaoXinControl_Loaded(null, null);
                }
            };
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImageButton_Click_1(object sender, RoutedEventArgs e)
        {
            if (dgList.SelectedItem != null)
            {
                var letter = dgList.SelectedItem as WordActionService.Word_XingZhengJieShaoLetter;
                if (letter != null)
                {
                    wind = new XingZhengJieShaoXinWindow((int)letter.ID);
                    wind.Show();
                    wind.Closed += (sender1, e1) =>
                    {
                        if (wind.DialogResult == true)
                        {
                            XingZhengJieShaoXinControl_Loaded(null, null);
                        }
                    };
                }
            }
        }

        private void delete_Click(object sender, RoutedEventArgs e)
        {
            if (dgList.SelectedItem != null)
            {
                var letter = dgList.SelectedItem as WordActionService.Word_XingZhengJieShaoLetter;
                _client.DeleteWord_XingZhengJieShaoLetterAsync(letter.ID);
            }
            else
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("");
            }
        }
    }
}
